<?php echo $this->headLink()->appendStylesheet('/css/redmond/jquery-ui-1.8.5.custom.css') ?>
<script type="text/javascript" src="/jquery/jquery.validate.js"></script> 
<script type="text/javascript">
     window.setTimeout('window.location="/product/findseller"; ',0000);
</script>
<script type="text/javascript">
$(document).ready(function() { 
	$("#frmLogin").validate({
		highlight: function(element, errorClass) {
	    	$(element).css({ backgroundColor: "rgb(240,150,150)"});
	    },
	    unhighlight: function(element, errorClass) {
	        $(element).css({ backgroundColor: "rgb(160,255,165)"});
	    },
	    rules:
        {
	    	"username": {
	        	required: true
	        },
	        "password": {
	        	required: true,
	       		minlength: 6
	        }
        },
	    messages: {
        	"username": {
	       		required: "請輸入電郵地址"
	        },
	        "password": {
	       		required: "請輸入密碼",
	       		minlength: "最少6位數字密碼"
	        }
        }
	});
});
</script>
<div id="index">
	<form id="frmLogin" method='post' action='/member/login/re/sell'>
		<table>
			<tr>
				<td><input id="txtUsername" type='text' name='username' placeholder="電郵地址"/></td>
				<td><input id="txtPassword" type='password' name='password' placeholder="密碼"/></td>
				<td><input id="btnLogin" class="yellow-button" type='submit' name='login' value='登入'></td>
			</tr>
		</table>
	</form>
<!-- 
	<div id="i-header">
		<div id="menu">
			<a href="/product/findseller">主頁</a>&nbsp;
			<input type="text" name="criteria" placeholder="輸入關鍵字"/>
			<select>
				<option>所有分類</option>
			</select>
			<select>
				<option>所有拍賣品</option>
			</select>
			<input type="submit" value="搜尋"/>
			<input type="submit" value="進階搜尋"/>
		</div>
	</div>
	<div id="i-content">
		<div id="i-left">
			<form id="prodForm" method='post' action='<?php echo $this->escape($this->action); ?>' enctype='multipart/form-data'>
				<table>
					<tr>
						<td><label><?php echo $this->escape($this->title);?></label></td>
						<td><input type="text" name="title" size="30" maxlength="20"/></td>
					</tr>
					<tr>
						<td><label><?php echo $this->escape($this->status);?></label></td>
						<td><input type="text" name="status" size="3" maxlength="3"/>%</td>
					</tr>
					<tr>
						<td><label><?php echo $this->escape($this->image);?></label></td>
						<td><input type="file" name="imgFile"></td>
					</tr>
					<tr>
						<td><label><?php echo $this->escape($this->description);?></label></td>
						<td><textarea name="description" rows="5" cols="25"></textarea></td>
					</tr>
					<tr>
						<td><label><?php echo $this->escape($this->price);?></label></td>
						<td><input type="text" name="price"/></td>
					</tr>
					<tr>
						<td><label><?php echo $this->escape($this->validDate);?></label></td>
						<td><input type="text" name="day" size="1" maxlength="2"/><?php echo $this->day;?></td>
					</tr>
					<tr>
						<td><label><?php echo $this->escape($this->tradeMethod);?></label></td>
						<td>
							<input type="radio" name="payGroup" value="pf" checked><label><?php echo $this->payFirst;?></label>&nbsp;
							<input type="radio" name="payGroup" value="pl"><label><?php echo $this->payLater;?></label>&nbsp;
							<input type="radio" name="payGroup" value="pd"><label><?php echo $this->payDeposit;?></label>
						</td>
					</tr>
					<tr>
						<td><label><?php echo $this->escape($this->delivery);?></label></td>
						<td>
							<input type="radio" name="deliveryGroup" value="f" checked><label><?php echo $this->face;?></label>&nbsp;
							<input type="radio" name="deliveryGroup" value="m"><label><?php echo $this->mail;?></label>&nbsp;
						</td>
					</tr>
					<tr>
						<td><label><?php echo $this->escape($this->payment);?></label></td>
						<td>
							<input type="checkbox" name="paypal" value="Y"><?php echo $this->escape($this->paypal);?>&nbsp;
							<input type="checkbox" name="bank" value="Y"><?php echo $this->escape($this->bankTransfer);?>&nbsp;
							<input type="checkbox" name="cheque" value="Y"><?php echo $this->escape($this->cheque);?>&nbsp;
							<input type="checkbox" name="others" value="Y"><?php echo $this->escape($this->others);?>
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<input type="submit" value="<?php echo $this->escape($this->submit);?>"/>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div id="i-right">
			<table id="item-list">
				<?php 
					for($i=0; $i<sizeof($this->prodBuyEntries); $i++){
						if($i % 2 == 0){
							echo "<tr><td>";
						}
						else{
							echo "<td>";
						}
					?>
						<div>
							<img src="<?php echo $this->prodBuyEntries[$i]->image;?>" width="84px" height="60px"></img>
							<b><a href='<?php echo $this->escape($this->bidAction) . "/pid/" . $this->prodBuyEntries[$i]->product_buy_id; ?>'>
								<?php echo $this->prodBuyEntries[$i]->title;?></a></b>
							<?php 
								echo "(" . $this->prodBuyEntries[$i]->new . $this->new . ")<br/>";
							?>
							<?php echo $this->username;?><br/>
						</div>
					<?php			
						if($i % 2 == 0){
							echo "</td>";
							if($i + 1 == sizeof($this->prodBuyEntries)){
								echo "<td></td></tr>";
							}
						}
						else{
							echo "</td></tr>";
						}
					}
					?>
			</table>
		</div>
	</div>-->
</div>
<?php 
require_once '/fb/facebook-php-sdk-42481fa/src/facebook.php';
	
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
	'appId'  => '354578754618136',
	'secret' => '3eeb1509e2cd4a6faa369eb80c99ebc6',
));

// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl(array(
  	'next'=>'http://www.thingslook.com/member/logout')
  );
} else {
  $loginUrl = $facebook->getLoginUrl(array(
  	'scope' => 'email,user_hometown,user_photos')
  );
}

// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');
echo $loginUrl;
?>
<?php if ($user): ?>
	<a href="<?php echo $logoutUrl; ?>">Logout</a>
	<?php 
			echo $user_profile['user_photos'];
			echo $user_profile['email'];
			echo $user;
			
			
	?>
<?php ?>
<?php else: ?>
	<div>
		<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
		<?php ?>
	</div>
<?php endif ?>